import java.util.Objects;

/**
 * 抽象二元运算类（仅支持加法、减法）
 */
public abstract class BinaryOperation2 {
    protected int leftOperand;
    protected int rightOperand;
    protected char operator;
    private int value;

    public BinaryOperation2(int leftOperand, int rightOperand, char operator) {
        this.leftOperand = leftOperand;
        this.rightOperand = rightOperand;
        this.operator = operator;
        this.value = calculate();
    }

    protected abstract int calculate();

    public abstract boolean checkingCalculation();

    public int getLeftOperand() {
        return leftOperand;
    }

    public int getRightOperand() {
        return rightOperand;
    }

    public char getOperator() {
        return operator;
    }

    public int getValue() {
        return value;
    }

    public void setLeftOperand(int leftOperand) {
        this.leftOperand = leftOperand;
        this.value = calculate();
    }

    public void setRightOperand(int rightOperand) {
        this.rightOperand = rightOperand;
        this.value = calculate();
    }

    @Override
    public String toString() {
        return leftOperand + " " + operator + " " + rightOperand + " = " + value;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        BinaryOperation2 that = (BinaryOperation2) obj;
        return leftOperand == that.leftOperand &&
                rightOperand == that.rightOperand &&
                operator == that.operator;
    }

    @Override
    public int hashCode() {
        return Objects.hash(leftOperand, rightOperand, operator);
    }
}